package pro5_decoder_encoder.ex2_encoder;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import pro5_decoder_encoder.ex2_encoder.bean.Msg;


public class  MyServerHandler extends SimpleChannelInboundHandler<Object> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object obj) throws Exception {
        Channel incoming = ctx.channel();
        if (obj instanceof Msg) {
            Msg msg = (Msg) obj;
            System.out.println("客户端->服务器:" + incoming.remoteAddress() + msg.getBody());
            incoming.write(obj);
        }
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();
    }
}
